<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/ui/common/footer.xsl"/>
<xsl:variable name="host"><xsl:value-of select="document('/host.xml')//configuration/host"/></xsl:variable>
<xsl:variable name="tmp"><xsl:value-of select="document('/const.xml')//const/node[1]/@id"/></xsl:variable>
<xsl:variable name="class"><xsl:value-of select="html/@c"/></xsl:variable>
<xsl:variable name="page"><xsl:value-of select="html/@p"/></xsl:variable>
<xsl:variable name="size"><xsl:value-of select="html/@s"/></xsl:variable>
<xsl:variable name="url">/index.aspx?c=<xsl:value-of select="$class" />&amp;s=<xsl:value-of select="$size" />&amp;p=</xsl:variable>
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" doctype-public="-//W3C//DTD XHTML 1.1//EN" indent="yes" encoding="utf-8" />
<xsl:template match="/html">
	<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title><xsl:value-of select="head/title"/> - "<xsl:value-of select="document('/host.xml')//configuration/name" /></title>
			<link rel="icon" type="image/x-icon" href="/favicon.ico" />
			<link rel="stylesheet" type="text/css" href="/ui/index.css" />
			<script type="text/javascript" src="/js/lib.js"></script>
			<xsl:call-template name="script" />
		</head>
		<body>
			<div class="syblog_main_frame">
				<div class="syblog_head">
					<div class="syblog_logo">
						<img src="/ui/img/logo.jpg" />
					</div>
					<div class="syblog_ctrl_contain">
						<div class="syblog_ctrl_bar">
							<div class="syblog_login">
								<div>
									<form id="syblog_login_form" action="/login.aspx" onsubmit="return false">
										<span>用户名：</span><input name="account" style="ime-mode:disabled" dataType="Account" min="3" max="32" msg="您输入的用户名不正确" type="text" size="16" maxlength="20" />
										<span>密码：</span><input name="pwd" min="5" max="32" msg="您输入的密码不正确" type="password" size="16" />
										<input type="checkbox" name="autologin" id="autologin" /><label for="autologin">自动登录</label>
										<input type="image" src="/ui/img/login.gif" onclick="userlogin(this.form)" />
										<a href="/register.xml" target="register">注册</a>
										<a href="/forgetpwd.xml" target="forgetpwd">找回密码</a>
									</form>
								</div>
								<div id="syblog_login_show">
									<xsl:apply-templates select="document('/checklogin.aspx')//message" />
								</div>
							</div>
							<div class="syblog_bookmark">
								<a href="/help.xml">帮助</a>
							</div>
						</div>
						<div class="syblog_link">
							<ul>
								<li><a href="/">首页</a></li>
								<li><a href="http://www.muchool.com">码库</a></li>
								<li><a href="http://bbs.muchool.com">论坛</a></li>
								<li><a href="http://club.muchool.com">俱乐部</a></li>
							</ul>
							<span></span>
						</div>
						<div class="syblog_search">
							<form class="syblog_search_form" target="_self" action="/search.aspx" method="GET" onsubmit="return (this.elements['wd'].value.trim().length > 0)">
								<input tyte="text" name="wd" size="45" onkeypress="if(event.keyCode == 13 &amp;&amp; this.value.trim().length > 0)this.form.submit()" />
								<input type="submit" value="搜索" />
							</form>
						</div>
					</div>
				</div>
				<div class="syblog_index">
					<div class="syblog_pop">共<span><xsl:value-of select="ceiling(number(body/span) div number($size))"/></span>页<span><xsl:value-of select="body/span"/></span>篇文章</div>
					<a>当前位置</a><span>&gt;&gt;</span><a href="index.aspx">文章分类</a>
					<xsl:if test="number($class)&gt;0">
						<xsl:choose>
							<xsl:when test="number($class) &lt; 100">
								<span>&gt;&gt;</span>
								<a href="index.aspx?c={$class}"><xsl:value-of select="document('/const.xml')//const/node[1]/node[number($class)]/@name"/></a>
							</xsl:when>
							<xsl:otherwise>
								<xsl:call-template name="index">
									<xsl:with-param name="mclass">
										<xsl:value-of select="substring($class,1,string-length($class)-2)"/>
									</xsl:with-param>
								</xsl:call-template>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:if>
				</div>
				<div class="syblog_main_middle">
					<div class="syblog_main_middle_left">
						<div class="syblog_class_title">文章分类目录</div>
						<div class="syblog_class_list">
							<dl>
								<xsl:choose>
									<xsl:when test="$class='0'">
										<dt><a href="index.aspx">全部分类</a></dt>
										<xsl:apply-templates select="document('/const.xml')//const/node[1]/node"/>
									</xsl:when>
									<xsl:when test="number($class) &lt; 100">
										<xsl:call-template name="node">
											<xsl:with-param name="mclass">
												<xsl:value-of select="$class"/>
											</xsl:with-param>
										</xsl:call-template>
									</xsl:when>
									<xsl:otherwise>
										<xsl:call-template name="node">
											<xsl:with-param name="mclass">
												<xsl:value-of select="substring($class,1,string-length($class)-2)"/>
											</xsl:with-param>
										</xsl:call-template>
									</xsl:otherwise>
								</xsl:choose>
							</dl>
						</div>
					</div>
					<div class="syblog_main_middle_right">
						<table cellpadding="0" cellspacing="0">
							<thead>
								<tr>
									<td>标题</td>
									<td width="80">作者</td>
									<td width="120">发表日期</td>
									<td width="60">浏览</td>
									<td width="60">评论</td>
								</tr>
							</thead>
							<tbody>
								<xsl:apply-templates select="body/p"/>
							</tbody>
					  </table>
					  <xsl:if test="number(body/span)>number($size)">
							<div class="syblog_pager">
								<xsl:call-template name="pager">
									<xsl:with-param name="p">
										<xsl:value-of select="ceiling(number(body/span) div number($size))"/>
									</xsl:with-param>
								</xsl:call-template>
							</div>
						</xsl:if>
					</div>
					<div class="clear:both;height:1px;overflow:hidden"></div>
				</div>
				<xsl:call-template name="footer" />
			</div>
		</body>
		<script type="text/javascript">
		<![CDATA[
			checklogin();
		]]>
		</script>
	</html>
</xsl:template>
<xsl:template match="body/p">
	 <tr>
	 	<xsl:if test="position() mod 2 = 0">
	 		<xsl:attribute name="class">double</xsl:attribute>
	 	</xsl:if>
		<td><div class="title"><a target="_blank" href="{a[1]/@href}"><xsl:value-of select="a[1]"/></a></div></td>
		<td><div class="author"><a target="_blank" href="{a[2]/@href}"><xsl:value-of select="a[2]"/></a></div></td>
		<td><xsl:value-of select="span[1]"/></td>
		<td><xsl:value-of select="span[2]"/></td>
		<td><xsl:value-of select="span[3]"/></td>
	 </tr>
</xsl:template>
<xsl:template match="node">
	<dd><a href="index.aspx?c={@id}"><xsl:value-of select="@name"/></a></dd>
</xsl:template>
<xsl:template name="node">
	<xsl:param name="mclass" />
	<dt><a href="index.aspx?c={$mclass}"><xsl:value-of select="document('/const.xml')//const/node[1]/node[number($mclass)]/@name"/></a></dt>
	<xsl:apply-templates select="document('/const.xml')/const/node[1]/node[number($mclass)]/node"/>
</xsl:template>
<xsl:template match="/message">
	<div class="syblog_user_control">
		<xsl:choose>
			<xsl:when test="string-length(@account)>0">
				<span id="syblog_login_user"><xsl:value-of select="@name" />&#160;(<xsl:value-of select="@private" />/<xsl:value-of select="@system" />)</span><a id="syblog_manage_button" href="/{@account}/#/ui/common/manager.htm" target="_blank">管理</a>
				<script type="text/javascript">
					user.account="<xsl:value-of select="@account" />".toLowerCase();
					user.name="<xsl:call-template name="captureDoubleQuot"><xsl:with-param name="processText" select="@name" /></xsl:call-template>";
				</script>
			</xsl:when>
			<xsl:otherwise>
				<span id="syblog_login_user"></span><a id="syblog_manage_button" target="_blank">管理</a>
			</xsl:otherwise>
		</xsl:choose>
		<a href="#" onclick="logout();return false">注销</a>
	</div>
</xsl:template>
<xsl:template name="script">
	<script type="text/javascript">
		<![CDATA[
			var User = function() {
				this.account = "";
				this.name = "";
			};
			var user = new User();
			function userlogin(f) {
				$(f).post(function(r){
					var msg = r.getXML().documentElement;
					user.account = msg.getAttribute("account");
					user.name = msg.getAttribute("name");
					setLoginInfo(msg.getAttribute("private"),msg.getAttribute("system"));
				});
			}
			function checklogin() {
				if(user.account.length > 0) {
					$id("syblog_login_show").style.display = "block";
					$id("syblog_login_form").parentNode.style.display = "none";
				}
			}
			function setLoginInfo(p,s) {
				checklogin();
				$id("syblog_login_user").innerText = user.name + " (" + p + "/" + s + ") ";
				$id("syblog_manage_button").href = "/" + user.account + "#/ui/common/manager.htm";
			}
			function logout() {
				var xmlhttp = new HTTPRequest(true,true,false);
				xmlhttp.send("/login.aspx",null);
				$id("syblog_login_show").style.display = "none";
				$id("syblog_login_form").parentNode.style.display = "block";
			}
		]]>
	</script>
</xsl:template>
<xsl:template name="index">
	<xsl:param name="mclass" />
	<span>&gt;&gt;</span>
	<a href="index.aspx?c={$mclass}"><xsl:value-of select="document('/const.xml')//const/node[1]/node[number($mclass)]/@name"/></a>
	<span>&gt;&gt;</span>
	<a href="index.aspx?c={$class}"><xsl:value-of select="document('/const.xml')//const/node[1]/node[number($mclass)]/node[@id=$class]/@name"/></a>
</xsl:template>
<xsl:template name="pager">
	<xsl:param name="p"/>
	<xsl:if test="$p>1">
		<xsl:if test="($page)>1">
			<a target="_self" href="{$url}{number($page)-1}">上一页</a>
		</xsl:if>
		<xsl:call-template name="loop">
			<xsl:with-param name="min">
				<xsl:choose>
					<xsl:when test="$p>10 and $page>5">
						<xsl:choose>
							<xsl:when test="$p>$page+5">
								<xsl:value-of select="number($page)-5"/>
							</xsl:when>
							<xsl:otherwise><xsl:value-of select="number($p)-10"/></xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>1</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
			<xsl:with-param name="max">
				<xsl:choose>
					<xsl:when test="$p>10">
						<xsl:choose>
							<xsl:when test="$p>$page+5">
								<xsl:choose>
									<xsl:when test="$page>5">
										<xsl:value-of select="number($page)+5"/>
									</xsl:when>
									<xsl:otherwise>10</xsl:otherwise>
								</xsl:choose>
							</xsl:when>
							<xsl:otherwise><xsl:value-of select="$p"/></xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="$p"/></xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
		</xsl:call-template>
		<xsl:if test="$p>number($page)">
			<a target="_self" href="{$url}{number($page)+1}">下一页</a>
		</xsl:if>
	</xsl:if>
</xsl:template>
<xsl:template name="loop">
	<xsl:param name="min"/>
	<xsl:param name="max"/>
	<xsl:if test="$max>=$min">
		<xsl:choose>
			<xsl:when test="$min=$page">
				<span>
					<xsl:value-of select="$min"/>
				</span>
			</xsl:when>
			<xsl:otherwise>
				<a target="_self" href="{$url}{$min}">[<xsl:value-of select="$min" />]</a>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:call-template name="loop">
			<xsl:with-param name="min">
				<xsl:value-of select="number($min)+1"/>
			</xsl:with-param>
			<xsl:with-param name="max">
				<xsl:value-of select="$max"/>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:if>
</xsl:template>
<xsl:template name="captureDoubleQuot">
	<xsl:param name="processText"/>
	<xsl:choose>
		<xsl:when test="contains($processText, '&quot;')">
			<xsl:value-of select="substring-before($processText,'&quot;')" />
			<xsl:text>\&amp;quot;</xsl:text>
			<xsl:call-template name="captureDoubleQuot">
				<xsl:with-param name="processText" select="substring-after($processText,'&quot;')"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$processText"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
</xsl:stylesheet>